import configparser
import os
import platform

environment = 'dev'

PNAME = 'ai-dps-flask'
config = configparser.ConfigParser()


def read(path, section, option):
    config.read_file(open(path))
    return config.get(section, option)


def getLogFilePath():
    current_path = os.path.abspath(__file__)
    root_path = current_path[:current_path.find(PNAME) + len(PNAME)]
    path = root_path + '/log'
    return path


def getlogFileName():
    current_path = os.path.abspath(__file__)
    root_path = current_path[:current_path.find(PNAME) + len(PNAME)]
    path = '%s/log/%s.log' % (root_path, PNAME)
    return path


def getConfigFile():
    current_path = os.path.abspath(__file__)
    root_path = current_path[:current_path.find(PNAME) + len(PNAME)]
    sys_str = platform.system()
    if sys_str == 'Windows':
        path = r"" + root_path + "\config\config_" + environment + ".ini"
    else:
        path = root_path + "/config/config_" + environment + ".ini"
    return path


def readConfig(section, option):
    config.read_file(open(getConfigFile()))
    return config.get(section, option)
